﻿using System;
using System.Text.RegularExpressions;

namespace Baula.TextGen.Framework.Sections
{
    public class PlaceholderSection : ISection
    {
        private const string BeginTokenRegexPattern = "' %Section:(.*)%";  // TODO: make more flexible

        public static bool IsBegin(string line)
        {
            var regex = new Regex(BeginTokenRegexPattern);

            return regex.IsMatch(line);
        }

        private readonly string _headingLine;

        public string HeadingLine
        {
            get { return _headingLine; }
        }

        public PlaceholderSection(string headingLine)
        {
            _headingLine = headingLine;
            Name = GetPlaceholderSectionName(headingLine);
        }

        private string GetPlaceholderSectionName(string headingLine)
        {
            var regex = new Regex(BeginTokenRegexPattern);

            return regex.Match(headingLine).Groups[1].Value;
        }

        public string Content
        {
            get { throw new NotSupportedException("The PlaceholderSection is a single line section and does not have a content."); }
        }

        public string Name { get; private set; }

        public void AppendLine(string line)
        {
            throw new NotSupportedException("The PlaceholderSection is a single line section and does not have any content-lines.");
        }
    }
}